<style type="text/css">
    .demo-upload-list {
        display: inline-block;
        width: 60px;
        height: 60px;
        text-align: center;
        line-height: 60px;
        border: 1px solid transparent;
        border-radius: 4px;
        overflow: hidden;
        background: #fff;
        position: relative;
        box-shadow: 0 1px 1px rgba(0, 0, 0, .2);
        margin-right: 4px;
    }

    .demo-upload-list img {
        width: 100%;
        height: 100%;
    }

    .demo-upload-list-cover {
        display: none;
        position: absolute;
        top: 0;
        bottom: 0;
        left: 0;
        right: 0;
        background: rgba(0, 0, 0, .6);
    }

    .demo-upload-list:hover .demo-upload-list-cover {
        display: block;
    }

    .demo-upload-list-cover i {
        color: #fff;
        font-size: 20px;
        cursor: pointer;
        margin: 0 2px;
    }

    .selected-search {
        box-shadow: 0 1px 6px rgba(0, 0, 0, .2);
        height: 200px;
        width: 260px;
        position: relative;
        border-radius: 4px;
    }

    .selected-search .search-action {
        position: absolute;
        top: 10px;
        left: 10px;
        right: 10px;
    }

    .selected-search .selected-arr {
        position: absolute;
        top: 50px;
        left: 20px;
        right: 20px;
        bottom: 10px;
        overflow: scroll;
    }

    .select-click {
        border: 1px solid #dddee1;
        border-radius: 4px;
        padding: 0 10px;
        margin-bottom: 10px;
    }

    .selected-search .selected-arr .selected-item {
        /*border-bottom: 1px solid #dfdfdf;*/
    }
</style>
<template>
    <!--<div></div>-->
    <i-form ref="formValidate" :model="formValidate" :rules="ruleValidate" :label-width="100">
        <template v-for="(item,index) in dataModel">
            <Form-item :label="item.value" :prop="item.Keyname">
                <i-input v-model="formValidate[item.Keyname]" :placeholder="'请输入'+ item.value + '(非必填)'"></i-input>
            </Form-item>
        </template>
        <Form-item>
            <i-button @click="handleSubmit('formValidate')" type="primary">提交</i-button>
        </Form-item>
    </i-form>
</template>
<script>
    import apiUtil from '../../assets/utils/api_util';
    import baseUtil from '../../assets/utils/base-util';

    export default {
        data() {
            return {
                formValidate: {
                },
                ruleValidate: {},
                expandInfoArr: [],
                dataModel:[],
                keyword: '',
                //分配用户id
                userId:'',
                //值班人员选择操作
                principalId: '',
                principalArr: [],
                personalName: '请选择组织',
                selectPeopelIsShow: false,

            }
        },
        props: {
            newUserId:'',
        },
        mounted: function () {
            this.getListAllUserExt();
        },
        created:function(){
            this.userId = this.$route.query.id;
        },

        methods: {
            handleSubmit(name) {

                let that = this;
                let model = this.$refs[name].model;
                console.log('提交数据:', model);
                this.$refs[name].validate((valid) => {
                    that.addData(model);
                })
            },
            //跳转
            jumpPage: function (id, url) {
                //跳转
                let route = '';
                if (id.length > 0) {
                    route = {
                        path: url,
                        query: {
                            id: id
                        },
                    };
                } else {
                    route = {
                        path: url,
                    };
                }

                console.log()
                this.$router.push(route);
            },
            //获取拓展信息字段
            getListAllUserExt: function () {
                let that = this;
                let para = {};
                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.ListAllUserExt, para, function (res) {
                    that.$Loading.finish();

                    that.expandInfoArr = res.Msg;
                    res.Msg.forEach(function (item, index) {
                        let itemSub ={};
                         itemSub.Keyname =item.Keyname;
                         itemSub.value = item.Value;
                        that.dataModel.push(itemSub);
                    });
                });
            },
            getSearchData() {
                let that = this;

                let para = {
                    keyword: this.keyword,
                };

                this.$Loading.start();

                apiUtil.get(that, apiUtil.urls.OrganSearch, para, function (res) {
                    that.$Loading.finish();
                    that.principalArr = res.Msg;
                });
            },
            choosePeople: function (id, name) {
                this.principalId = id;
                this.personalName = name;
                this.selectPeopelIsShow = false;

            },
            //添加
            addData: function (model) {
                let that = this;


                if(that.newUserId){
                    let postJosn = [];

                    // model.organizationId = this.principalId;

                    for (let i in model) {
                        let postValue = {
                            'extkey': '',
                            'extValue': '',
                        };

                        postValue.extkey = i;
                        postValue.extValue = model[i];

                        postJosn.push(postValue);
                    }

                    let apiPost = {
                        id: that.newUserId,
                        // id: this.$route.query.id,
                        extJson: JSON.stringify(postJosn),
                    };


                    let params = that.$qs.stringify(apiPost);
                    this.$Loading.start();

                    apiUtil.post(that, apiUtil.urls.userCreateStep4, params, function (res) {
                        that.$Loading.finish();

                        // that.$Modal.confirm({
                        //     title: '操作成功',
                        //     content: '请选择下一步操作',
                        //     okText: '继续添加',
                        //     cancelText: '返回人员列表',
                        //     onOk: () => {
                        //         baseUtil.pageJump(that, '', 'UserAdd')
                        //
                        //     },
                        //     onCancel: () => {
                        //         baseUtil.pageJump(that, '', 'UserList')
                        //     }
                        // });
                        that.$Notice.open({
                            title: '提示',
                            desc: '拓展信息添加成功 '
                        });

                    });
                }else {

                    that.$Notice.open({
                        title: '提示',
                        desc: '请先在"基本信息"添加人员 '
                    });
                }

            },

        }
    }
</script>
